package org.jboss.seam.example.divo.domain;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.TableGenerator;

import org.hibernate.validator.NotNull;
import org.jboss.seam.annotations.Name;

import com.divo.core.json.JSONObject;

@Entity
@Name("hotel")
public class Hotel implements Serializable
{
   private int id;
   private String name;
   private String address;
   private String city;
   private String state;
   private String zip;
   private String country;
   private BigDecimal price;
   
   @Id 
   @GeneratedValue(strategy = GenerationType.TABLE, generator="nextid")
   @TableGenerator(name="nextid", table="T_NextId")
   public int getId()
   {
      return id;
   }
   public void setId(int id)
   {
      this.id = id;
   }
   
   @NotNull
   public String getName()
   {
      return name;
   }
   public void setName(String name)
   {
      this.name = name;
   }
   
   @NotNull
   public String getAddress()
   {
      return address;
   }
   public void setAddress(String address)
   {
      this.address = address;
   }
   
   @NotNull
   public String getCity()
   {
      return city;
   }
   public void setCity(String city)
   {
      this.city = city;
   }
   
   @NotNull
   public String getZip()
   {
      return zip;
   }
   public void setZip(String zip)
   {
      this.zip = zip;
   }
   
   @NotNull
   public String getState()
   {
      return state;
   }
   public void setState(String state)
   {
      this.state = state;
   }
   
   @NotNull
   public String getCountry()
   {
      return country;
   }
   public void setCountry(String country)
   {
      this.country = country;
   }

   @Column(precision=6, scale=2)
   public BigDecimal getPrice()
   {
      return price;
   }
   public void setPrice(BigDecimal price)
   {
      this.price = price;
   }
   
   @Override
   public String toString()
   {
      return "Hotel(" + name + "," + address + "," + city + "," + zip + ")";
   }
   
   public String toJSON() {
       try {
           return toJSONObject().toString();
       }
       catch (Exception e) {
           //LOGGER.debug("toJSON exception\n" + e);
           return null;
       }
   }
   
   public JSONObject toJSONObject() {

       try {
           JSONObject jsonObject = new JSONObject();
           jsonObject.put("id", id);
           jsonObject.put("name", name);
           jsonObject.put("address", address);
           jsonObject.put("city", city);
           jsonObject.put("state", state);
           jsonObject.put("zip", zip);
           jsonObject.put("country", country);
           jsonObject.put("price", price);
           
           return jsonObject;
       }
       catch (Exception e) {
           //LOGGER.error("toJSON exception\n" + e);
           return null;
       }
   }
   
}
